/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cpasl;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

/**
 *
 * @author seanm_000
 */
public class InitialGroup extends GridPane {
    
    public InitialGroup(Stage stage) {
        
        setAlignment(Pos.CENTER);
        setHgap(10);
        setVgap(10);
        setPadding(new Insets(25, 25, 25, 25));
        
        Label participantIdLabel = new Label("Participant ID");
        add(participantIdLabel, 0, 0);
        
        final TextField participantIdTextField = new TextField();
        add(participantIdTextField, 1, 0);
        
        final ToggleGroup primeGroup = new ToggleGroup();
        final RadioButton prime1Button = new RadioButton("Prime 1");
        prime1Button.setToggleGroup(primeGroup);
        prime1Button.setSelected(true);
        final RadioButton prime2Button = new RadioButton("Prime 2");
        prime2Button.setToggleGroup(primeGroup);
        primeGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
            public void changed(ObservableValue<? extends Toggle> ov,
                Toggle old_toggle, Toggle new_toggle) {
                if (new_toggle != null) {
                    String text = ((RadioButton) new_toggle).getText();
                    CpaslManager.getInstance().setPrime1(text.equals("Prime 1"));
                }                
            }
        });
        add(prime1Button, 0, 1);
        add(prime2Button, 0, 2);
        
        Button readyButton = new Button();
        readyButton.setText("Ready?");
        readyButton.setId("ready-button");
        readyButton.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
               CpaslManager.getInstance().setParticipantId(participantIdTextField.getText());
               CpaslManager.getInstance().setPrime1(prime1Button.isSelected());
               CpaslManager.getInstance().switchToDisplay(Groups.INSTRUCTIONS_NEXT, 250);
            }
        });
        add(readyButton, 0, 3);
    }
    
}
